package Control;

import java.util.Date;

import Entity.Customer_CustomerMembership;
import Entity.User;
import Form.Customer_CreateCustomerMembership;
import Form.Customer_UpdateCustomerProfile;
import Form.Workshop_UpdateWorkshop_Form;

public class Customer_Controller {
	private Customer_CustomerMembership newMembership = new Customer_CustomerMembership(); 

	public Customer_Controller(){}
	
	public Customer_Controller(Customer_UpdateCustomerProfile parser){
		this.parser = parser;
	}
	
	public boolean createMembership(String nric, String name,
			String username, String email, int contact_no, Date dob,
			String address, char gender, String security_qn,
			String security_ans, String race_status_code,
			String user_status_code,String custPassword,  String custSignUpDate,String custLogInTime,
			String custLogInDate, String userType) {

		
			newMembership = new Customer_CustomerMembership(nric, name, username, email, contact_no, dob, address, gender, security_qn, security_ans
					, race_status_code, user_status_code, custPassword, custSignUpDate, custLogInTime, custLogInDate, userType);
		
		boolean success = newMembership.createMembership();
		return success; 
	}
	
	public User verifyUser(String userName, String password){
		User u = new User();
		u.loginUser(userName, password);
		return u;
	}
	
	public User checkUser(String userName){
		User u = new User();
		u.checkMember(userName);
		return u;
	}
	private Customer_UpdateCustomerProfile parser;
	private Customer_UpdateCustomerProfile getParser() {
		return parser;
	}
	
	public void setParser(Customer_UpdateCustomerProfile parser) {
		this.parser = parser;
	}
	
	public void updateMembership(){
		
		if(parser.u.getCustomerUserType().equals("CORPORATE")){
			parser.u.setContact_no(Integer.parseInt(getParser().getCContactNum().getText()));
			parser.u.setAddress(getParser().getCAddress().getText());
			parser.u.setEmail(getParser().getCEmail().getText());
		}
		else if(parser.u.getCustomerUserType().equals("INDIVIDUAL")){
			parser.u.setContact_no(Integer.parseInt(getParser().getIContactNum().getText()));
			parser.u.setAddress(getParser().getIAddress().getText());
			parser.u.setEmail(getParser().getIEmail().getText());
		} 

		parser.u.updateUserRecord();
	}
	
	public void updatePassword(){ 
		parser.u.setPassword(new String(getParser().getPF_NewPwd().getPassword())); 
		parser.u.updateUserPassword();
	}

	public void resetPassword(User u){
		u.updateUserPassword();
	}
	
	public void deactivate(){
		parser.u.updateUserStatus();
	}
	public User retrieveSecQnsAns(String nric){
		User u = new User();
		u = u.retrieveSecQnsAns(nric);
		return u;
	}


}
